
const _createStaticSprite = ('_createStaticSprite');
const _createSprite = ('_createSprite');
const _error = Symbol('_error');
export default class UtilsSprite {
    constructor(_data, _type, _that) {
        if (!_data) return this[_error]('no data?');
        this.data = _data;
        _type === 'static' ? this[_createStaticSprite](_that) : this[_createSprite](_that);
    }

    [_createSprite](_that) {
        this.data.forEach(element => {
            _that[element.key] = _that.physics.add.sprite(element.sprXY.x, element.sprXY.y, element.spriteKey);
            _that[element.key].body.setAllowGravity(element.ag);
            _that[element.key].body.setGravityY(element.gy);
            _that[element.key].setBounce(element.boun);
            _that[element.key].setCollideWorldBounds(element.cwb);
            element.vis ? _that[element.key].setVisible(false) : _that[element.key].setVisible(true);
            element.play ? _that[element.key].play(element.play) : null;
            element.off ?  _that[element.key].setOffset(element.off.x, element.off.y) : null;
            element.scal ? _that[element.key].setScale(element.scal) : null;
            element.setData ? _that[element.key].setData(element.setData) : null;
            element.setPipe ? _that[element.key].setPipeline('Light2D') : null;
        });
    }

    [_createStaticSprite](_that) {
        this.data.forEach(element => {
            _that[element.key] = _that.physics.add.staticSprite(element.sprXY.x, element.sprXY.y, element.spriteKey);
            element.vis ? _that[element.key].setVisible(false) : _that[element.key].setVisible(true);
            element.play ? _that[element.key].play(element.play) : null;
            element.scal ? _that[element.key].setScale(element.scal) : null;
            element.setData ? _that[element.key].setData(element.setData) : null;
            element.setPipe ? _that[element.key].setPipeline('Light2D') : null;
        });
    }

    [_error](err) {
        throw err;
    }
}